#include <config.h>
#include <stdio.h>
#include <string.h>
static ItemCfg g_tItemCfg[ITEMCFG_MAX_COUNT];
static int g_tItemcfg_count = 0;
int ParseConfigFile(void)
{
	FILE * pfd;
	char buf[100];
	char * p = buf;
	pfd = fopen(CFG_FILE , "r");
	if(!pfd)
	{
		printf("fopen err\n");
		return -1;
	}
	while(fgets(buf , 100 , pfd))
	{	buf[99] = '\0';
		p = buf;
		while(*p == ' ' || *p =='\t')
			p++;
		if(*p == '#')
			continue;
		g_tItemCfg[g_tItemcfg_count].command[0] = '\0';
		g_tItemCfg[g_tItemcfg_count].index = g_tItemcfg_count;
		sscanf(p , "%s %d %s" , g_tItemCfg[g_tItemcfg_count].name , &g_tItemCfg[g_tItemcfg_count].bCanBeTouched, \
			g_tItemCfg[g_tItemcfg_count].command);
		g_tItemcfg_count++;
	}
	return 0;	
}

int ItemCfgCount(void)
{
	 return g_tItemcfg_count;
}
PItemCfg GetItemConfigBy_index(int index)
{
	if(index < g_tItemcfg_count)
		return &g_tItemCfg[index];
	else 
		return NULL;
}
PItemCfg GetItemConfigBy_name(char * name)
{
	int i;
	for (i = 0; i < g_tItemcfg_count; i++)
	{
		if (strcmp(name, g_tItemCfg[i].name) == 0)
			return &g_tItemCfg[i];
	}
	return NULL;
}


